package cuit.cx.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class NetTransfver {
	
	
	
	public static String getJson(String parameter){
		String url = StaticConstant.REQUEST_URL + parameter;
		String jsonString = "";
		
		HttpClient httpClient = new DefaultHttpClient();
		HttpGet get = new HttpGet(url);
		try {
			HttpResponse response = httpClient.execute(get);
			if(response.getStatusLine().getStatusCode() == 200)
			{
				InputStream is = response.getEntity().getContent();
				BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8"));
				
				StringBuffer sb = new StringBuffer();
				String temp = null;
				while((temp = br.readLine()) != null)
				{
					sb.append(temp);
				}
				jsonString = sb.toString();
				System.out.println("cx:"+sb.toString());
			}
			
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return jsonString;
	}
	

}
